
import { useMount } from "ahooks"
import { useRequest } from "alova/client"
import { lazy, Suspense, useState } from 'react'

import { Http } from '../../Utils/Api'
import { AddIndexdDB } from '../../Utils/IndexedDB'

const LoadSvg = lazy(() => import('../../View/Loading/LoadSvg'))

const CommonManagement = () => {
    const [LoginPage, setLoginPage] = useState()
    const [SignPage, setSignPage] = useState()
    const { send } = useRequest(() => Http({ url: 'getAdminA06ProjectConfig' }), { immediate: false })

    useMount(() => {
        send().then(async res => {
            const { loginPage, signPage } = res.theme
            const SignPage = lazy(() => import(`../../View/SignPage/${signPage}.jsx`))
            const LoginPage = lazy(() => import(`../../View/LoginPage/${loginPage}.jsx`))
            await AddIndexdDB('config', res)
            setSignPage(SignPage)
            setLoginPage(LoginPage)
        })
    })

    return (
        <Suspense fallback={<LoadSvg />}>
            {(SignPage && LoginPage) ? <LoginPage title='公共平台' SignPage={SignPage} btnText='登录' /> : <LoadSvg />}
        </Suspense>
    );
};

export default CommonManagement;